﻿@{
    ViewBag.Title = Model.BookName+"-章节目录";
    IEnumerable<CW_BookChapter> chapters = ViewBag.chapters as IEnumerable<CW_BookChapter>;

    ViewBag.keywords = Model.BookName + "," + Model.BookName + "最新章节,2眼看书网";
    ViewBag.description = "【2眼看书】" + Model.BookName + "," + Model.Author + "," + Model.Descriotion;
}
@model CW_Book

<div class="chapter">
    <div class="listHeader am-text-center">
        <h1>@Model.BookName</h1>
        @if (!string.IsNullOrEmpty(Model.Author))
        {
            <span>作者：@Model.Author</span>
        }
        <a onclick="changeSort(this);" class="am-margin-left am-btn am-btn-secondary am-btn-xs">倒叙<i class="am-icon-long-arrow-down"></i></a>
    </div>
    <div class="listBox">
        <div class="am-g am-text-sm chapterItem">
            @foreach (var item in chapters)
            {
                <a class="am-u-sm-12 am-u-md-4 am-u-end" href="@Url.Action("Chapter", "Book", new { bid=item.BookId,cid=item.Id})">
                    @item.ChapterName
                </a>
            }
        </div>
    </div>
</div>
@section Scripts{
  <script>
      var arrStr = @Html.Raw(ViewBag.jaonChapter);
      var isReverse=false;
      function changeSort(obj)
      {
          arrStr.reverse();
          var chaptersItem="";
          arrStr.forEach(function(item){
              chaptersItem+="<a class=\"am-u-sm-12 am-u-md-4 am-u-end\" href=\"/Book/Chapter/@Model.Id/"+item.Id+"\">";
              chaptersItem+=item.ChapterName;
              chaptersItem+="</a>";
          })
          $(".chapterItem").html(chaptersItem);
          isReverse=!isReverse;
          if(isReverse)
          {
              $(obj).html("顺序<i class=\"am-icon-long-arrow-up\"></i>");              
          }
          else
          {
              $(obj).html("倒序<i class=\"am-icon-long-arrow-down\"></i>");
          }
         
      }
  </script>


}
